/*
 * GenClst_Algorithm.h
 *
 *  Created on: May 28, 2011
 *      Author: nzhao
 */

#ifndef GENCLST_ALGORITHM_H_
#define GENCLST_ALGORITHM_H_

#include "share/Usrdef.h"
#include "share/parameters.h"
#include "core/globalvars.h"
#include "share/gsl_app.h"

const int	MAX_CLST_NUM = 5000000;
const int	MAX_CLST_ORDER  = 10;
const int 	MAX_VOLUME = 1000;
extern int * LINK_MAP;


struct Sublist
{
	int sublen;
	int * sublist;
};

class Single_Cluster
{
public:
	void initialization(int n, int * p_idx);
	void set_Subs(int * val, int num);
	void append_Sup(int sup);
	void clear();

	int my_nspin(){return nspin;};
	int * mySpinIdx(){return spinIDX;};
	int my_subNum(){return sub_num;};
	int * my_Subs(){return subIDX;};
	int my_supNum(){return sup_num;};
	int * my_Sups(){return supIDX;};

	int seqIDX;
private:
	int nspin;
	int * spinIDX;
	int sub_num;
	int * subIDX;
	int sup_num;
	int * supIDX;
};

class Cluster_List
{
public:
	void initialize();
	void generate_from_order(int order_n);
	void find_sub_clusters();

	int  Total_Clst(){return nCLST;};
	int  NUM_order(int i){return num_of_order[i];};
	Single_Cluster * index(int n){return(clsts+n);};

	void clear();

private:
	int nCLST;
	int bath_spin_num;

	int start_of_order  [MAX_CLST_ORDER];
	int end_of_order    [MAX_CLST_ORDER];
	int num_of_order    [MAX_CLST_ORDER];

	Single_Cluster temp_clst, *temp_search;
	int	temp_idxlist[2*MAX_CLST_ORDER];
	int temp_sub[MAX_CLST_ORDER];
	int	temp_search_res[MAX_VOLUME];

	int	growth_by(Single_Cluster mom, int current_n);
	int * legal_and_accept_element(Single_Cluster mom, int idx);
	int  find_Sgl_subsets(Single_Cluster clst, int nspin);

	Single_Cluster * clsts;

};

#endif /* GENCLST_ALGORITHM_H_ */
